var e = require("../@babel/runtime/helpers/regeneratorRuntime"),
  t = require("../@babel/runtime/helpers/asyncToGenerator");
Component({
  properties: {},
  data: {
    active: ""
  },
  methods: {
    onClickTab: function (r) {
      var that = this;
      wx.getSetting({
        withSubscriptions: true,
        success(res) {
          console.log(res)
          if (res.subscriptionsSetting.mainSwitch) { // 用户打开了订阅消息总开关
            if (res.subscriptionsSetting.itemSettings != null) { // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
              let moIdState = res.subscriptionsSetting.itemSettings['O3By8L9KTFTSqtTutSFQjbKja60tf1sq6yHm4c6NF5c']; // 用户同意的消息模板id
              if (moIdState === 'accept') {
                console.log('接受了消息推送');
              } else if (moIdState === 'reject') {
                console.log('拒绝了消息推送');
                that.requestSubscribeMessage()
              } else if (moIdState === 'ban') {
                console.log("已被后台封禁");
              }
            } else {
              that.requestSubscribeMessage()
            }
          } else {
            //这里做用户未开启订阅总开关的操作

            //是否提示用户前去设置
            wx.openSetting({
              withSubscriptions: true,
            })

          }
        }
      })
      wx.switchTab({
        url: r.currentTarget.dataset.path,
        fail: function (params) {
          console.log(params)
        }
      })
    },
    requestSubscribeMessage() {
      // wx.requestSubscribeMessage({
      //   tmplIds: ['O3By8L9KTFTSqtTutSFQjbKja60tf1sq6yHm4c6NF5c'], // 模板ID 一次调用最多可订阅3条消息
      //   success(res) {
      //     //这里会返回用户订阅是否订阅
      //   }
      // })
    }
  },
  
  lifetimes: {
    created: function () {},
    ready: function () {
      var e = $.getCurrentPage();
      if (e) {
        var t = e.route;
        "pages/index/index" === t && this.setData({
          active: "index"
        }), "pages/personal/index" === t && this.setData({
          active: "personal"
        }), "pages/recruit/index" === t && this.setData({
          active: "recruit"
        }), "pages/workbench/index" === t && this.setData({
          active: "call-record"
        }), "pages/deadbeat/index" === t && this.setData({
          active: "deadbeat"
        })
      }
    }
  },
  pageLifetimes: {
    show: function () {}
  }
});